<template>
  <a-card :bordered="false">
  <a-row>
    <a-col :md="24">
      <div class="doc-info">
        <!--<div>上级名称：{{fileData.eqpBelong}}</div>-->
        <div>文件名称：{{fileData.fileTitle}}</div>
        <div>文件类型：{{fileData.fileTypes}}</div>
        <div>上传时间：{{fileData.createTime}}</div>
        <div>上传者：{{fileData.createBy}}</div>
        <div>
          <a-button @click="collection(2)" :disabled="iscollected" type="primary">加入收藏</a-button>
        </div>
      </div>
      <iframe :src="fileSrc" width="100%" :height="domH" style="border: 1px solid #e8e8e8; padding-top: 20px"></iframe>
      <!--<img alt="doc" style="width: 100%" :src="fileSrc" />-->
    </a-col>
  </a-row>
  </a-card>
</template>
<script>

  import {addFileDrcInfo,isFileDrcDetails} from '@/api/digitization'

  import {randomUUID,formatTime } from '@/utils/util.js'

  import store from '@/store/'
  import ACol from "ant-design-vue/es/grid/Col";

  export default {
    name: 'dataAccess',
    components: {
      ACol

    },
    props:{
      viewDocData:{
        type: Object,
        default(){
          return {}
        }
      }
    },
    watch: {
      viewDocData: {
        deep: true,
        handler(n,o) {
          let {fileSrc,fileData} = n;
          if(!fileSrc) return;
          this.fileSrc = fileSrc;
          this.fileData = JSON.parse(fileData);

          this.isConllected();
        }
      }
    },
    data() {
      return {
        height: 700,
        currFlowId: '',
        currFlowName: '',
        keyword: '',
        recommend:[''],
        pageSize: 10,
        totalSize: 500,
        infoList:[
          /*{
            fileMixName:'',
            fileDescription:'',
            createTime:'',
            createBy:''
          }*/
        ],
        uploadFileUrl:[
          /*{
            fileName: "附件2：员工转正申请表.docx",
            filePath: "http://192.168.2.125:8080/jeecg-boot/sys/common/static/tdm/附件2：员工转正申请表_1598585548301.docx",
            fileSize: 22245
          }*/
        ],
        isShow: true,
        currentDoc:{},
        userInfo: {},
        iscollected: false,
        fileSrc: '',
        fileData: {},
        domH: document.documentElement.clientHeight - 163
      }
    },
    created(){
      console.log(store.getters.userInfo)
      this.userInfo = store.getters.userInfo;

      this.init();
    },
    mounted(){
      this.isConllected();
      this.collection(0);
    },
    methods:{
      init(){
        // let {fileSrc,fileData} = this.$route.query
        let {fileSrc,fileData} = this.viewDocData;
        this.fileSrc = fileSrc;
        this.fileData = JSON.parse(fileData);

        console.log(this.fileSrc,this.fileData)
      },
      isConllected(){
        isFileDrcDetails({
          pid: this.fileData.pid,
          userid: this.userInfo.username
        }).then(res => {
          if(res.result.length){
            this.iscollected = true
          }else{
            this.iscollected = false
          }
        })
      },
      onSearch(val){
        this.$router.push({
          path:'/technology/dataAccess/view',
          query:{
            keyword:val
          }
        })

      },
      searchkey(val){
        this.keyword = val;
        this.onSearch(val);
      },
      collection(val){
        console.log(this.currentDoc.fileid);
        let {createBy,username,createTime,updateBy,updateTime,orgCode} = this.userInfo
        let params = {};
        let obj = {};
        let obb = {};
        obj = {
          id:randomUUID(),
          createBy:username,
          createTime,
          updateBy,
          updateTime,
          sysOrgCode:orgCode,
          fileId:this.fileData.fileid
        }
        obb = {
          id:randomUUID(),
          createBy:username,
          createTime,
          updateBy,
          updateTime,
          sysOrgCode:orgCode,
          drcType:val,     //0阅读1下载2收藏
          fileId:this.fileData.fileid
        }
        params = {
          obj,obb
        }
        addFileDrcInfo(params).then(res => {
          console.log(val);
          if(val){
            if (res.success) {
              this.iscollected = true;
              this.$message.success(res.message)
            } else {
              this.$message.warning(res.message)
            }
          }
        })
      },
      downloadDoc(){
        let fileMixName = this.$route.query.fileName;
        let path = window._CONFIG['minioURL'] + '/tdm/tdm/'+fileMixName;
        window.open(path)

        this.collection(1);

      }


    },
  }
</script>
<style scoped>

</style>
<style lang="less" scoped>
  .recommend{
    width: 70%;
    margin: 20px auto;
    color: #02b5f0;
    span{
      color: #021c32;
      padding: 5px 15px;
      background: #03b5f1;
      border-radius: 10px;
      display: inline-block;
      margin-left: 10px;
      cursor: pointer;
    }
  }
  .result{
    margin-bottom: 20px;
  }
  .con-list{
    margin-bottom: 20px;
    .title{
      color: #00c;
      cursor: pointer;
      text-decoration: underline;
    }
    .remark{
      span{
        margin-right: 30px;
      }
    }
  }
  .doc-info{
    border: 1px solid #e8e8e8;
    display: flex;
    /*justify-content: space-between;*/
    /*align-items: center;*/
    padding: 10px;
    /*color: #02b5f0;*/
    color: #333;
    div{
      padding-bottom: 10px;
      padding-left: 20px;
      line-height: 30px;
    }
    .remark{
      span{
        color: #ccc;
        margin-right: 20px;
      }
    }
  }
</style>